package com.akw.boot3.core.service;

import com.akw.boot3.core.entity.UserEntity;
import com.akw.boot3.core.event.LoginSuccessEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

@Service
public class CouponService {

    public void sendCoupon(String username) {
        System.out.println("username:" + username + "随机得到了一张优惠券");
    }

    @Order(2)
    @EventListener
    public void onApplicationEvent(LoginSuccessEvent event) {
        UserEntity source = (UserEntity) event.getSource();
        sendCoupon(source.getUsername());
    }
}
